package DS0419;

public class LoopQueue {
    private final int max = 6;
    private String arr[]  = new String[max];
    private int front = 0;
    private int rear = 0;
    //插入
    public void enQueue(String date){
        if( (rear+1)%max==front){
            System.out.println("队列已满");
            return;
        }
        arr[rear] =date;
        rear=(rear+1)%max;
    }
    //清除
    public void delQueue(){
        if(rear==front){
            System.out.println("队列已空");
            return;
        }
        front=(front+1)%max;
    }
    //长度
    public int length(){
        return rear-front+max;
    }
    //清零
    public void clear(){
        front = 0;
        rear = 0;
    }
    //打印
    public void display(){
        if(rear==front){
            System.out.println("此队列为空");
            return;
        }
        else{
            if(front<rear){
                for (int i=front;i<rear;i++){
                    System.out.print(arr[i] +"  ");
            }}
            else{
                    for(int i=front;i<max;i++){
                        System.out.print(arr[i]+"  ");
                        for(int j=0;j<rear;j++){
                            System.out.print(arr[j] + "  ");
                        }

                    }
                }

            System.out.println();
        }
    }
}
